/*
 * @author: Reynier Ortiz
 * @date: Nov 15, 2013
 */
$(function() {
    var successMsgContainer = $("div[id*=successMessageContainer]");
    var errorMsgContainer = $("div[id*=errorMessageContainer]");
    var successMsg = $("span[id*=successMessage]");
    var errorMsg = $("span[id*=errorMessage]");

    $("button[id*=editClassWork]").click(editClassWork);
    $("button[id*=deleteClassWork]").click(deleteClassWork);
    $("button[id*=gradeClassWork]").click(gradeClassWork);


    if (successMsg.text())
        successMsgContainer.show();
    if (errorMsg.text())
        errorMsgContainer.show();

    function editClassWork() {
        copyClassWorkId(this);
        $("button[id*=addClassWork]").click();
    }

    function copyClassWorkId(elem) {
        var classWorkIdToEdit = $(elem).siblings("input[id*=edit_classWorkId]").val();
        $("input[class*=classWorkId]").val(classWorkIdToEdit);
    }

   function deleteClassWork() {
        if (confirm("Are you sure you want to delete this Class Work?")) {
            copyClassWorkId(this);
            $("button[id*=submitDeleteClassWork]").click();
        }
    }

    function gradeClassWork() {
        //create a classworkId hidden input for the viewGrades form
        copyClassWorkId(this);
        $("button[id*=submitGradeClassWork]").click();
    }

});
